import 'package:flutter/material.dart';
import 'package:flutterappyidongjingfen/Extension/touch_callback.dart';
import 'package:flutterappyidongjingfen/Views/TabPageViews.dart';
import 'package:flutterappyidongjingfen/SecondControllers/AchievementBrowse.dart';

class FinancicalPage extends StatefulWidget{
  @override
  FinancicalState createState() => FinancicalState();
}

class FinancicalState extends State<FinancicalPage>{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      backgroundColor: Color.fromRGBO(11, 13, 28, 1),
      body:listView(context)
    );
  }
}


Widget listView(BuildContext context){
  return Container(
    margin: EdgeInsets.only(bottom: 0,left: 5,right: 5,top: 10),
    child: ListView(
    children: <Widget>[
      titleCard("核心指标","24,000","存款余额（亿）"),
      Container(
        child: Card(
          shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
          child: buttonSection(context),
          color: Color(0xFF23283C),
        ),
      ),
      cardwith("一般存款",context,(){ Navigator.pushNamed(context, 'dispositPage');}),
      cardwith("零售存款",context,(){print("零售存款被点击");}),
      cardwith("公司存款",context,(){print("公司存款被点击");}),
      ],
    ),
  );
}


Widget cardwith(String title,BuildContext context,Function func){
  return Container(
    height: 250,
    child: Card(
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
      color: Color(0xFF23283C),
      child: Column(
        children: <Widget>[
          cardTitleRow(title,context,func),
          RichText(
              textAlign: TextAlign.center,
              text: TextSpan(
                  children: [
                    TextSpan(
                      text: "亿",
                      style: TextStyle(fontSize: 15,color: Color(0xFF119CFD)),
                    )
                  ],
                  text: "150.75",
                  style: TextStyle(fontSize: 42.0,color: Color(0xFF119CFD),
                  )
              )
          ),

//          Text("150.75亿",textAlign: TextAlign.center,style: TextStyle(fontSize: 42,color: Color(0XFF119CFD)),),
          CompareRow(),
          Text("更新时间：2019-04-12",textAlign: TextAlign.center,style: TextStyle(fontSize: 12,color: Color(0XFF7981A0)),),
          Padding(padding: EdgeInsets.only(bottom: 10)),
          dividerLine(),
          bottomQuestion()
        ],
      )
      ),
    );
}

Widget cardTitleRow(String title,BuildContext context,Function func){
  return Container(

    margin: EdgeInsets.fromLTRB(15, 10, 0, 10),
    child: Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          SizedBox(
            width: 3,
            height: 16,
            child: Container(
//              color: Colors.blue,
              decoration: ShapeDecoration(
                color: Colors.blue,
                shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(1.5)),
              ),
            ),
          ),
          Padding(padding: EdgeInsets.only(left: 8)),
          Expanded(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Text(
                  title,
                  style: TextStyle(fontSize: 16.0,color: Colors.white),
                ),
              ],
            ),
          ),
        TouchCallBack(
            child:  Container(
                alignment: AlignmentDirectional.topStart,
                margin: const EdgeInsets.only(right: 12.0,top: 5.0),
                child: Icon(Icons.chevron_right,color: Colors.white38)
            ),
//            onPressed: (){
//              Navigator.pushNamed(context, 'dispositPage');
//              print("${title}被点击");
//            },
            onPressed: func,
            background: Colors.black12,
        )

        ],
    ),
  );
}

Widget CompareRow(){
  return Container(
    margin: EdgeInsets.only(top: 10,bottom: 10),
    child: Row(
      mainAxisAlignment: MainAxisAlignment.spaceAround,
      children: <Widget>[
        Column(
          children: <Widget>[
            Text("比上日",style: TextStyle(fontSize: 13,color: Color(0xFF7981A0))),
            Row(
              children: <Widget>[
                Icon(Icons.arrow_upward,color: Color(0xFFFF3F77),size: 16.0,),
                Text("3.48亿",style: TextStyle(color: Color(0xFFFF3F77),fontSize: 16.0),)
              ],
            )
          ],
        ),
        Column(
          children: <Widget>[
            Text("比上月",style: TextStyle(fontSize: 13,color: Color(0xFF7981A0))),
            Row(
              children: <Widget>[
                Icon(Icons.arrow_upward,color: Color(0xFFFF3F77),size: 16.0),
                Text("100亿",style: TextStyle(color: Color(0xFFFF3F77),fontSize: 16.0),)
              ],
            )
          ],
        ),
        Column(
          children: <Widget>[
            Text("比年初",style: TextStyle(fontSize: 13,color: Color(0xFF7981A0))),
            Row(
              children: <Widget>[
                Icon(Icons.arrow_downward,color: Color(0xFF1AEFBA),size: 16.0),
                Text("100亿",style: TextStyle(color: Color(0xFF1AEFBA),fontSize: 16.0),)
              ],
            )
          ],
        ),
      ],
    ),
  );
}

Widget dividerLine(){
  return Container(
    margin: EdgeInsets.fromLTRB(15, 10, 15, 0),
    child: Divider(height: 1.0,color: Color.fromRGBO(11, 13, 28, 1))
  );
}

Widget bottomQuestion(){
  var isFavorite = false;
  return Container(

    margin: EdgeInsets.only(top: 13.5,left: 0,right: 0),
    child: Row(
      mainAxisAlignment: MainAxisAlignment.spaceAround,

      children: <Widget>[
         TouchCallBack(
             child:  Row(
               children: <Widget>[
                 Icon(Icons.chat,color: Colors.white70,size: 16,),
                 Text("提问",style: TextStyle(fontSize: 13.0,color: Colors.white70))
               ],
             ),
             onPressed: (){print("提问");}),
        TouchCallBack(
            child:  Row(
                children: <Widget>[
                  Icon(Icons.favorite_border,color: Colors.white70,size: 16,),
                  Text("关注",style: TextStyle(fontSize: 13.0,color: Colors.white70))
                ],
            ),
            onPressed: (){print("关注");})
      ],
    ),
  );
}


Widget buttonSection(BuildContext context){
  return Container(
    margin: EdgeInsets.fromLTRB(0, 20, 0, 20),
    child: Stack(
      children: <Widget>[
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: [
            _buildButtonColumn(Colors.blue, Image.asset("images/icon_Financical_jingyingribao.png"), '经营日报',context),
            _buildButtonColumn(Colors.blue, Image.asset("images/icon_Financical_jingyingyebao.png"), '经营月报',context),
            _buildButtonColumn(Colors.blue, Image.asset("images/icon_Financical_yejikanban.png"), '业绩看板',context),
            _buildButtonColumn(Colors.blue, Image.asset("images/icon_Financical_duibiaofenxi.png"), '对表分析',context),
          ],
        )
      ],
    ),
  );
}

Widget _buildButtonColumn(Color color, Image image, String label,BuildContext context) {
  return TouchCallBack(
    onPressed: (){
      print("业绩看板");
      Navigator.pushNamed(context, 'AchievementBrowsePage');
    },
    child: Column(
      mainAxisSize: MainAxisSize.min,
//    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
      children: [
        image,
        Container(
          margin: const EdgeInsets.only(top: 12),
          child: Text(
            label,
            style: TextStyle(
              fontSize: 13,
              fontWeight: FontWeight.w400,
              color: Colors.white,
            ),
          ),
        ),
      ],
    ),
  );
}